#include <bits/stdc++.h>

using namespace std;

int rs232c_encode(double *volts, int volts_size, const char *msg, int size)
{
    int required = size * 9;
    if (volts_size < required)
        return -1;

    int idx = 0;
    for (int i = 0; i < size; i++)
    {
        uint8_t c = msg[i] & 0x7F;
        volts[idx++] = 15;

        for (int j = 0; j < 7; j++)
        {
            int bit = (c >> j) & 1;
            volts[idx++] = bit ? -15 : 15;
        }

        volts[idx++] = -15;
    }
    return required;
}

int rs232c_decode(char *msg, int size, const double *volts, int volts_size)
{
    int msg_idx = 0;
    int volt_idx = 0;

    while (volt_idx < volts_size && msg_idx < size)
    {
        if (volts[volt_idx] >= 0)
        {
            if (volt_idx + 8 >= volts_size)
                break;

            uint8_t byte = 0;
            for (int j = 0; j < 7; j++)
            {
                double v = volts[volt_idx + 1 + j];
                byte |= ((v < 0) ? 1 : 0) << j;
            }

            if (volts[volt_idx + 8] < 0)
            {
                msg[msg_idx++] = (char)byte;
            }
            volt_idx += 9;
        }
        else
        {
            volt_idx++;
        }
    }
    return msg_idx;
}

int main()
{
    char *msg;
    cin >> *msg;
    double volts[100];
    char decoded_msg[10];

    int volts_size = rs232c_encode(volts, 100, msg, 1);
    if (volts_size == -1)
    {
        cout << "Error: Voltage buffer too small!\n";
        return 1;
    }

    cout << "Encoded voltage sequence:\n";
    for (int i = 0; i < volts_size; i++)
    {
        cout << volts[i] << " ";
    }
    cout << endl;

    // 解码
    int decoded_size = rs232c_decode(decoded_msg, 10, volts, volts_size);
    if (decoded_size == -1)
    {
        cout << "Error: Decoding failed!\n";
        return 1;
    }

    cout << "Decoded message: " << decoded_msg;

    return 0;
}